package com.abel.controller;

import com.abel.factory.Factory;
import com.abel.factory.Factory1;
import com.abel.tactics.Handler;
import com.abel.templat.TemplateMethodHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 返回类型处理
 *
 * @author heyangyang
 * @since 2024-05-15
 */

@RestController
@RequestMapping("/")
@Slf4j
public class TestController {

    @RequestMapping("{strateg}")
    public String test(@PathVariable String strateg){
        Handler invokeStrategy = Factory.getInvokeStrategy(strateg);
        invokeStrategy.AA(strateg);
        return "success" + strateg;
    }



    @RequestMapping("/2/{strateg}")
    public String test1(@PathVariable String strateg){
        TemplateMethodHandler invokeStrategy = Factory1.getInvokeStrategy(strateg);
        try {
            invokeStrategy.handle1();
        } catch (Exception e) {
            log.info("error{}", e.getMessage());
        }
        try {
            invokeStrategy.handler2();
        } catch (Exception e) {
            log.info("error{}", e.getMessage());
        }
        return "success" + strateg;
    }

}
